<template>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

    <el-form-item label="学号">
      <el-input v-model="ruleForm.studentid"></el-input>
    </el-form-item>
    <el-form-item label="学生姓名">
      <el-input v-model="ruleForm.studentname"></el-input>
    </el-form-item> <el-form-item label="课程号">
      <el-input v-model="ruleForm.courseid"></el-input>
    </el-form-item>
    <el-form-item label="课程名">
      <el-input v-model="ruleForm.coursename"></el-input>
    </el-form-item>
    <el-form-item label="考勤分数">
      <el-input v-model="ruleForm.classscore"></el-input>
    </el-form-item>
    <el-form-item label="作业分数">
      <el-input v-model="ruleForm.homescore"></el-input>
    </el-form-item>
    <el-form-item label="测试分数">
      <el-input v-model="ruleForm.testscore"></el-input>
    </el-form-item>
    <el-form-item label="最终分数">
      <el-input v-model="ruleForm.finalscore"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
      <el-button type="info" @click="back">返回</el-button>
      <el-button type="info" @click="test">test</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import axios from 'axios'

export default {
  data () {
    return {
      ruleForm: {
        studentid: '',
        studentname: '',
        score: ''
      },
      rules: {
        name: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios.post('http://localhost:8082/StudentManagement-Web/score/save.json', this.ruleForm).then(function (resp) {
            alert('success')
          })
        } else {
          console.log('失败!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    },
    back () {
      this.$router.replace('/Home')
    },
    test () {
      console.log(this.ruleForm)
    }
  }
}
</script>
